//$(function(){  });

//写cookies
function setCookie(name,value){
	var date = new Date();
	date.setTime(date.getTime() + 2*3600*1000);
	var str = name + "=" + escape(value);
	document.cookie = str+"; expires=" + date.toGMTString()+"; path=/";
}

//写cookies（无时间限制）
function setCookieNoLimit(name,value){
	var str = name + "=" + escape(value);
	document.cookie = str+"; path=/";
}

//读取cookie
function getCookie(NameOfCookie){
	if (document.cookie.length > 0){
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1){ 
			begin += NameOfCookie.length+1;//cookie值的初始位置 
			end = document.cookie.indexOf(";", begin);//结束位置 
			if (end == -1) end = document.cookie.length;//没有;则end为字符串结束位置 
			var cookieValue = unescape(document.cookie.substring(begin, end));
			return cookieValue;
		}
	}
	return "";
}

//删除cookies
function deleteCookie(name){
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=a; expires=" + date.toGMTString()+"; path=/";
}

//重设cookies
function resetCookie(name){
	var cookieValue = getCookie(name);
	if(cookieValue == ''){ return; }
	setCookie(name,cookieValue);
}

//读取并重设cookie
function getAndResetCookie(NameOfCookie){
	if (document.cookie.length > 0){
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1){ 
			begin += NameOfCookie.length+1;//cookie值的初始位置 
			end = document.cookie.indexOf(";", begin);//结束位置 
			if (end == -1) end = document.cookie.length;//没有;则end为字符串结束位置 
			var cookieValue = unescape(document.cookie.substring(begin, end));
			setCookie(NameOfCookie,cookieValue);
			return cookieValue;
		}
	}
	return "";
}